package com.hhh.petadopt.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hhh.petadopt.pojo.User;
import com.hhh.petadopt.service.RegisterService;
import com.hhh.petadopt.utils.JsonUtils;

/**
 * 注册页面
 * @author 杜镇声声
 *
 */
@Controller
public class registercontroller {
	@Autowired
	private RegisterService registerservice;
	
	//显示注册页面
	@RequestMapping(value="/register.html")
	public String showregister() {
		return "register";
	}
	//异步校验用户名是否存在
	@RequestMapping(value="/checkUsername.html")
	public void checkusernamee(String username,HttpServletResponse response) {
		
		boolean isExist = registerservice.selectserByUsername(username);
		//将isExit转换为json格式
		String da = JsonUtils.objectToJson(isExist);
		try {
			response.getWriter().write(da);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	//注册
	@RequestMapping(value="/registerin.html")
	@ResponseBody
	public String userRegister(User user) {
		//执行操作
		registerservice.register(user);
		return "ok";
	}
	

}
